import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;
 class  PersonSortable2 {
	private String name;
	private int age;
	public PersonSortable2(String name,int age){
		this.name=name;
		this.age=age;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String toString() {
		return name + "-" +age;
	}

	
}
  class  NameComparator implements Comparator<PersonSortable2>{

	@Override
	public int compare(PersonSortable2 arg0, PersonSortable2 arg1) {
		int x=arg0.getName().compareTo(arg1.getName());
		return x;
	}
  }
	class  AgeComparator implements Comparator<PersonSortable2>{

		@Override
		public int compare(PersonSortable2 arg0, PersonSortable2 arg1) {
			
			return arg0.getAge()-arg1.getAge();
		}

	 
	 
 }
 
public class Main {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt();
		PersonSortable2[] person=new PersonSortable2[n];
		for(int i=0;i<n;i++){
			person[i]=new PersonSortable2(input.next(),input.nextInt());
			}
		System.out.println("NameComparator:sort");
		Arrays.sort(person,new NameComparator());
		for(int i=0;i<n;i++){
			System.out.println(person[i]);
		}
		System.out.println("AgeComparator:sort");
		Arrays.sort(person,new AgeComparator());
		for(int i=0;i<n;i++){
			System.out.println(person[i]);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
}

}
